<?php

class ConfigForm extends FormModel {

    public $databaseName_;
    public $tablePrefix_;
    public $email_;
    public $username_;
    public $password_;
    public $password2_;
    public $language_ = Option::LANGUAGE_ENGLISH;
    public $sampleData_;

    public function init() {
        parent::init();
    }

    public function rules() {
        return array(
            array('databaseName_, tablePrefix_, email_, username_, password_, password2_', 'filter', 'filter' => 'trim'),
            array('email_, password_, password2_', 'required'),
            array('email_', 'length', 'max' => 50),
            array('email_', 'email', 'checkMX' => false),
            array('email_', 'unique', 'className' => 'User', 'attributeName' => 'email'),
            array('databaseName_, tablePrefix_, username_', 'length', 'max' => 10),
            array('password_, password2_', 'length', 'min' => 8, 'max' => 20),
            array('password_', 'ext.validators.PasswordStrengthValidator'),
            array('password_', 'compare', 'compareAttribute' => 'password2_'),
            array('databaseName_, tablePrefix_, email_, username_, password_, password2_, language_, sampleData_', 'safe'),
            array('captcha_', 'required', 'except' => 'register'),
            array('captcha_', 'ext.widgets.captchaExtended.CaptchaExtendedValidator', 'allowEmpty' => !CCaptcha::checkRequirements(), 'except' => 'register'),
            array('captcha_', 'safe', 'except' => 'register'),
            array('var_', 'ext.validators.BotDetectionValidator'),
            array('var_', 'safe'),
        );
    }

    public function attributeLabels() {
        return array(
            'databaseName_' => Lang::t('Database Name'),
            'tablePrefix_' => Lang::t('Table Prefix'),
            'email_' => Lang::t('Admin Email'),
            'username_' => Lang::t('Admin Username'),
            'password_' => Lang::t('Admin Password'),
            'password2_' => Lang::t('Re-type Admin Password'),
            'language_' => Lang::t('Select Language'),
            'sampleData_' => Lang::t('Import Sample Data'),
        );
    }

    public function getLanguageOption($id = null) {
        return Option::language($id);
    }

}//end class